/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import Control.Spil;
import Control.SpørgsmålHandler;
import database.DatabaseHandler;
import java.awt.CardLayout;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import model.Spørgsmål;
import utility.PageHandler;

/**
 *
 * @author Mikkel
 */
public class MainGUI extends javax.swing.JFrame {

    private Startskærm startSkærm;
    private SpørgsmålPanel spørgsmålPanel;
    private KategoriPanel kategori;
    private PageHandler ph;
    private SpørgsmålHandler sp;
    private DatabaseHandler db;
    private Spil spil;

    /**
     * Creates new form Kategori
     */
    public MainGUI() {
        initComponents();
        ph = new PageHandler((CardLayout) jPanel2.getLayout(), jPanel2);
        try {
            db = DatabaseHandler.getInstance();
            db.openConn();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(this, "Databasen eksisterer ikke");
        } catch (ClassNotFoundException ex) {
            JOptionPane.showMessageDialog(this, "Driveren ikke fundet");
        }
        try {
            sp = new SpørgsmålHandler();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(this, "Kunne ikke hente antal spørgsmål");
        }
        makePanels();
        setSize(690, 600);
        ph.show("startSkærm");
    }

    private void makePanels() {
        startSkærm = new Startskærm(this);
        kategori = new KategoriPanel();
        ph.addPage(startSkærm, "startSkærm");
        ph.addPage(kategori, "kategori");
    }

    public void showKategoriPanel() {
        ph.show("kategori");
    }

    public void showSpørgsmål() {
        spørgsmålPanel = new SpørgsmålPanel(this);
        ph.addPage(spørgsmålPanel, "spørgsmål");
        ph.show("spørgsmål");
    }

    public void showPoint() {
        ph.show("point");
    }

    public SpørgsmålHandler getSpørgsmålHandler() {
        return sp;
    }

    public void nytSpil(String spillernavn) {
        spil = new Spil(this, spillernavn);

    }

    public boolean tjekSvar(String svar) {
      
        boolean rigtigSvar = spil.tjekSvar(svar);
            jLabel1_rigtig.setText("Rigtige svar: "+spil.getRigtig());
            jLabel1_forkert.setText("Forkerte svar: "+spil.getForkert());
       
          return rigtigSvar;
    }
    
     public boolean tjekSvarUdenpoint(String svar) {
      
        boolean rigtigSvar = spil.tjekSvarUdenpoint(svar);
            jLabel1_rigtig.setText("Rigtige svar: "+spil.getRigtig());
            jLabel1_forkert.setText("Forkerte svar: "+spil.getForkert());
       
          return rigtigSvar;
    }
    

    public Spørgsmål getTilfældigtSpørgsmål() {
        return spil.getTilfældigtSpørgsmål();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        PointPanel = new javax.swing.JPanel();
        jLabel1_rigtig = new javax.swing.JLabel();
        jLabel1_forkert = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);
        getContentPane().setLayout(null);

        jPanel2.setLayout(new java.awt.CardLayout());
        getContentPane().add(jPanel2);
        jPanel2.setBounds(20, 68, 630, 400);

        javax.swing.GroupLayout PointPanelLayout = new javax.swing.GroupLayout(PointPanel);
        PointPanel.setLayout(PointPanelLayout);
        PointPanelLayout.setHorizontalGroup(
            PointPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PointPanelLayout.createSequentialGroup()
                .addContainerGap(86, Short.MAX_VALUE)
                .addGroup(PointPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1_forkert, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
                    .addComponent(jLabel1_rigtig, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        PointPanelLayout.setVerticalGroup(
            PointPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PointPanelLayout.createSequentialGroup()
                .addComponent(jLabel1_rigtig, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1_forkert, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        getContentPane().add(PointPanel);
        PointPanel.setBounds(430, 10, 240, 50);

        pack();
    }// </editor-fold>//GEN-END:initComponents
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel PointPanel;
    private javax.swing.JLabel jLabel1_forkert;
    private javax.swing.JLabel jLabel1_rigtig;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables
}
